package com.yly.doctorapp.picturebrowser;

import android.content.Context;
import android.support.v4.view.PagerAdapter;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.bumptech.glide.Glide;
import com.github.chrisbanes.photoview.PhotoView;
import com.yly.doctorapp.R;

import org.xutils.x;

import java.util.List;

/**
 * ProjectName: SmartBus
 * PackageName: com.zhcx.smartbus.ui.picturebrowser
 * description:
 * Date：2018/1/31 15:03
 * Author：Steven J
 * ClassName:${CLASS_NAME}
 * Modify The Note:
 **/

public class PictureAdapter extends PagerAdapter {
    private Context context;
    private List<String> mImageList;

    public PictureAdapter(Context context, List<String> mImageList) {
        this.context = context;
        this.mImageList = mImageList;
    }

    @Override
    public int getCount() {
        return mImageList != null ? mImageList.size() : 0;
    }

    @Override
    public boolean isViewFromObject(View view, Object object) {
        return view == object;
    }
    @Override
    public void destroyItem(ViewGroup container, int position, Object object) {
        container.removeView((View) object);
    }

    @Override
    public Object instantiateItem(ViewGroup container, int position) {
        View view = LayoutInflater.from(context).inflate(R.layout.layout_picture, container, false);
        PhotoView imageView = (PhotoView) view.findViewById(R.id.image_picture);
        Glide.with(context).load(mImageList.get(position).toString()).into(imageView);
//        x.image().bind(imageView, mImageList.get(position).toString());
        container.addView(view);
        return view;
    }
}
